<%@ page language="java" isELIgnored="false" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
	import="java.net.URLEncoder"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>抓取统计_手动持久化操作</title>

<link href="<%=request.getContextPath() %>/fare/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/show.js"></script>
<link href="<%=request.getContextPath()%>/fare/css/base.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/fare/js/datePicker/WdatePicker.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/jsFile/js_new/jquery.1.7.2.js" type="text/javascript"></script> 
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.all.js"></script>
 <script src="<%=request.getContextPath()%>/fare/lib/jquery/jquery.form.js"	type="text/javascript"></script>
<%-- <script src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script> --%>
<%-- <script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script> --%>
<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet" />
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<%-- <script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script> --%>
<%-- <script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/core/base.js" type="text/javascript"></script> --%>
<script src="<%=request.getContextPath()%>/fare/lib/json2.js" type="text/javascript"></script>
<%-- <link href="<%=request.getContextPath()%>/fare/js/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" /> --%>
<script type="text/javascript">

$(document).ready(function () {
	var $j = jQuery.noConflict();/* 这个很重要的，如果删除后面的ligerUI就用不了 */
	var griddata=${data};
	initializeP();
	manager=jQuery("#maingrid").ligerGrid({
		    dataAction : 'server',
		    title:'日志信息',
			showTitle:true,
		    columns : columns,
		    data: { Rows: griddata },
		  //  url:url,
		    height: '80%',
	        width: '100%',
	        pageSizeOptions : [20,40,50,100],
			pageSize:20, 
			pagesizeParmName:'pagesize' ,
			 rownumbers:false,
            /* enabledEdit: true,
            checkbox : false,
            clickToEdit:false,  */
	        isScroll: false,
	        usePager:true,
	    //    AllowPaging:true,
           heightDiff: 100
			 
	 	});   
});


/* 清空 数据
 */
function clearcontent(){	
	jQuery("#queryDate").val("");
	jQuery("#queryDate2").val("");
	jQuery("#select_frequency").val("");
}


function initializeP(){
	if('${startDateStr}' !=null && '${startDateStr}' !=""){
		jQuery("#queryDate").val('${startDateStr}');
		jQuery("#queryDate2").val('${endDateStr}');
		jQuery("#select_frequency").val('${frequency}');
	}

}

function find(){
	jQuery.noConflict();   
	var carrierKey=jQuery("#select_dpmt").val();	
	 jQuery("#dataForm").attr("action","<%=request.getContextPath()%>/registerCreateCodeAction!toRegisterCreateCodeJSP.action?carrierKey="+carrierKey);
	 jQuery("#dataForm").submit();
}
	
var nowDate  =  new Date().getTime();	
var  manager;	
var columns= [
			{ display: '序号', name: 'rowId', width: 40, 
				render: function(data, index) { 
					return (this.options.page-1)*this.options.pageSize+index+1;
					} 
			}, 
			{ display: '形式',width:50, align:'center',
				render:function (row){
					if(row.status==0){
						return "<b>自动</b>";
					}
					if(row.status==1){
						return "<b style=\'color:red\'>手动</b>";
					}
				}
			}, 
   			{ display: '创建日期',    name: 'createTime',width:140, isSort:true},
            { display: '开始时间', name: 'startTimeStr',width:140,isSort:true},
            { display: '结束时间', name: 'endTimeStr',width:140 ,isSort:true},
            { display: '日志',     name: 'taskLog',width:680, isSort:false},
            { display: '此次抓取日期', name: 'thisGrabDateStr', align: "left", width:80 ,isSort:true},
            { display: '下次开始时间',  name: 'nextTimeStr', width:140 ,isSort:true},
            { display: '下次抓取日期',  name: 'nextGrabDateStr', width:80, isSort:true}
            ];
 


//获取选中行信息
function getSelect() {
	var row = manager.getSelectedRow();
	if (!row) {
	//	$.ligerDialog.warn('请选您要操作的行！');
		return;
	} 
		return eval('(' + JSON.stringify(row) + ')');
	
}

function checkForm(){
	var startStr=jQuery("#queryDate").val();
	var date=startStr.split("-");
	var dD = new Date(date[0],date[1],date[2].split(" ")[0]);  
    dD.setDate(dD.getDate()+1);
    var year=dD.getFullYear();
    var month=dD.getMonth();
    var dates=dD.getDate();
    if(month<10){
    	month="0"+month;
    }if(dD.getDate()<10){
    	dates="0"+dates;
    }
	var endStr=year+"-"+month+"-"+dates+" 00:00";
	var freq=jQuery("#select_frequency").val();
	if(startStr==null|| startStr==""){
		alert("请选择开始段时间！");
		return false;
	}else if(jQuery("#queryDate2").val() ==null||jQuery("#queryDate2").val() ==""){
		if(	confirm("结束日期段时间为：'"+endStr+"'")){
			jQuery("#queryDate2").val(endStr);
			if(freq ==null ||freq==""){
				if(	confirm("抓取频率将为默认值:6小时/次")){
					jQuery("#select_frequency").val("6");
					return true;
				}else{
					return false;
				}
			}
		}else{
			return false;
		}
		
	}else{
		if(freq ==null ||freq==""){
			if(	confirm("抓取频率将为默认值:6小时/次")){
				jQuery("#select_frequency").val("6");
				return true;
			}else{
				return false;
			}
		}else return true;
	}
		
}


function doOperte(){
	var startStr=jQuery("#queryDate").val();
	if(checkForm()){
		var endStr=jQuery("#queryDate2").val();
		var fre=jQuery("#select_frequency").val();
		if(	confirm("确定处理此时间段"+startStr+"~"+endStr+"数据？")){
			jQuery("#wait").show();
			jQuery("#dataForm").ajaxSubmit({
				url:"<%=request.getContextPath()%>/persistenceOperteAction!toDoOperte.action",
				type:'post',
		        //dataType:'json',
				cache : false,
			    async : true,
			    
			    beforeSend:function(){},
			    success:function(data){
			    	if(data=='SUCCESS'){
			    		alert("操作成功！");
			    	}else{
			    		alert("操作失败原因!"+data);
			    		return ;
			    	}
			    	jQuery("#doOp").removeAttr("disabled");
			    	jQuery("#wait").hide();
			    	window.location.href="<%=request.getContextPath() %>/persistenceOperteAction!toOperteJsp.action";
			    },
			    error:function(){
			    	alert("操作失败！，请联系管理员！");
			    	jQuery("#doOp").removeAttr("disabled");
			    	jQuery("#wait").hide();
			    },
			    complete:function(){
			    	jQuery("#doOp").removeAttr("disabled");
			    	jQuery("#wait").hide();
			    }
			});
		}
	}
}

</script>

</head>	
<body >
	<div class="form_body">
		<div class="">
			<div class="form_table_tltle">手动持久化</div>
			<%-- 生成form--%>
			<form id="dataForm" method="post" action="">
				<input type="hidden" name="result" id="result" value=" " />
				<input type="hidden" name="status" id="status" value="1" />
				<table width="0" border="0" cellpadding="0" cellspacing="0" class="form_table">
					<tr>
						<td class="left" name="" id="">开始日期:</td>
						<td>
						<input name="startDateStr" type="text"	id="queryDate" style="width: 120px"    
					onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',maxDate:'%y-%M-%d 00:00:00',lang:'<s:text name='forms.locale'/>'})" readonly="readonly"/>
						</td>
						
						<td class="left" name="" id="">结束日期：</td>
						<td>
						<input name="endDateStr" type="text" id="queryDate2" style="width: 120px;"    
					onClick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',maxDate:'%y-%M-%d 00:00:00',lang:'<s:text name='forms.locale'/>'})" readonly="readonly"/>
						</td>
						
						<td class="left" id="frequency" name="frequency" style="width:120PX">执行频率(小时/次)：</td>
						<td>
						<select name="frequency" id="select_frequency">
							<option value="" >请选择</option>
							<c:forEach var="i" begin="0" end="23">
							        <option value="${i+1}">${i+1}</option>
						    </c:forEach>
							
						</td>
						
						<TD><img
							src="<%=request.getContextPath() %>/fare/images/button/but_13.png"
							name="doOp" id="doOp"
							onclick="javascript:doOperte()" /> <img
							src="<%=request.getContextPath() %>/fare/images/but_01.png"
							name="querybutton" id="querybutton"
							onclick="javascript:find();" /> <img
							src="<%=request.getContextPath() %>/fare/images/but_02.png"
							name="cancelbutton" id="cancelbutton"
							onclick="javascript:clearcontent();" /></TD>
					</tr>

				</table>
			</form>
			<!-- <div class="high_10"></div> -->
			<div  id="wait" style="display:none; text-align:center;" >
				<span ><font color="red"> 正在操作中，请耐心等候...</font></span>
			</div>
			<div id="maingrid" style="margin-top: 20px;"></div>
			

		</div>
	</div>

</body>
</html>